//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Data;
using CommunityServer.Components;

namespace CommunityServer.Blogs.Components
{
	/// <summary>
	/// Summary description for WeblogApplication.
	/// </summary>
	public class WeblogApplication : CSApplicationData
	{
		public WeblogApplication()
		{
			//
			// TODO: Add constructor logic here
			//
		}

        public override string Home
        {
            get{ return BlogUrls.Instance().Home;}
        }

        public override string SectionUrl(IContent ic)
        {
            if(ic != null)
            {

                IndexPost ip = ic as IndexPost;
                if(ip != null)
                    return BlogUrls.Instance().HomePage(ip.ApplicationKey);

                WeblogPost wp = ic as WeblogPost;
                if(wp != null)
                    return BlogUrls.Instance().HomePage(wp.Section.ApplicationKey);
            }

            return string.Empty;
        }

		public override string PostName
		{
			get
			{
				return ResourceManager.GetString("WeblogApplication_Post");
			}
		}

		public override string SectionName
		{
			get
			{
				return ResourceManager.GetString("WeblogApplication_Section");
			}
		}

		public override string GroupName
		{
			get
			{
				return ResourceManager.GetString("WeblogApplication_Group");
			}
		}

		public override string CategoryName
		{
			get
			{
				return ResourceManager.GetString("WeblogApplication_Category");
			}
		}

		#region Favorite Text

		public override string AddFavoritePostText
		{
			get
			{
				return ResourceManager.GetString("Favorites_Weblog_AddPost");
			}
		}

		public override string RemoveFavoritePostText
		{
			get
			{
				return ResourceManager.GetString("Favorites_Weblog_RemovePost");
			}
		}

		public override string AddFavoriteSectionText
		{
			get
			{
				return ResourceManager.GetString("Favorites_Weblog_AddSection");
			}
		}

		public override string RemoveFavoriteSectionText
		{
			get
			{
				return ResourceManager.GetString("Favorites_Weblog_RemoveSection");
			}
		}

		#endregion

	    public override IList Groups()
	    {
	        return WeblogGroups.GetWeblogGroups(true,false,false);
	    }

	    public override IList Sections()
	    {
	        return Weblogs.GetWeblogs(true,false,false);
	    }

	    public override IList SectionsByGroup(int groupID)
	    {
	        return Weblogs.GetWeblogsByGroupID(groupID,true,false,false);
	    }

	    public override ApplicationType ApplicationType
	    {
	        get { return ApplicationType.Weblog; }
	    }

	    public override string Name
	    {
	        get { return ResourceManager.GetString("weblogs"); }
	    }

	    public override string Url(Post post)
	    {
	        return BlogUrls.Instance().Post(post as WeblogPost);
	    }

	    public override Post InstantiatePost(IDataReader dr)
	    {
	       return WeblogDataProvider.PopulateWeblogEntryFromIDataReader(dr);
	    }

		public override Post GetPost(int postID)
		{
			return WeblogPosts.GetPost(postID, true, false, true);
		}

        public override bool Enabled
        {
            get { return WeblogConfiguration.Instance().Enabled;}
        }

        public override void SetEnabledStatus(bool enabled)
        {
            WeblogConfiguration config = WeblogConfiguration.Instance(false);
            config.Enabled = enabled;

            config.Save();
            
        }
	 


	}
}
